package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.domain.Product;
<<<<<<< HEAD
import cn.wolfcode.crm.service.IProductService;
=======
>>>>>>> 524224bf820c6d6da01f752551ee21b728709493
import cn.wolfcode.crm.domain.SafetyMechanism;
import cn.wolfcode.crm.page.PageResult;
import cn.wolfcode.crm.query.ProductQueryObj;
import cn.wolfcode.crm.service.IProductService;
import cn.wolfcode.crm.util.JsonResult;
import cn.wolfcode.crm.util.PermissionName;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;


@Controller
@RequestMapping("product")
public class ProductController {

    @Autowired
    private IProductService productService;

<<<<<<< HEAD
    @RequestMapping("list1")
    @ResponseBody
    public List<Product> list1 (Long smId,Long sStatus){

        List<Product> list = productService.list(smId,sStatus);

        return list;
     }
    @RequestMapping("listAll")
    @ResponseBody
    public List<Product> listAll (){

        List<Product> list = productService.listAll();

        return list;
     }
=======
>>>>>>> 524224bf820c6d6da01f752551ee21b728709493
    @RequestMapping("")
    @PermissionName("产品信息")
    public String index() {
        //只负责跳转到product.jsp页面即可
        return "product";
    }

    //产品信息
    @RequestMapping("list")
    @ResponseBody
    public PageResult list(ProductQueryObj qo) {

        PageResult result = productService.query(qo);
        return result;
    }
    //查询所有的保险机构
    @RequestMapping("selectAll")
    @ResponseBody
    public List selectAll() {

        return productService.selectALL();
    }
    @RequestMapping("selectSomeInfo")
    @ResponseBody
    public List<SafetyMechanism> selectSomeInfo() {
        List<SafetyMechanism> safetyMechanisms = productService.selectSomeInfo();
        return safetyMechanisms;
    }

    //编辑或者新增
    @RequestMapping("saveOrUpdate")
    @ResponseBody
    public JsonResult saveOrUpdate(Product product){
        JsonResult result = new JsonResult();
        try {
            if(product.getId() == null){
                productService.insert(product);
                result.setMessage("保存成功");
            }else{
                productService.update(product);
                result.setMessage("更新成功");
            }
        }catch (Exception e){
            e.printStackTrace();
            result.setMessage("操作失败");
        }
        return result;
    }
}
